#include "Bestand.h"

#include <fstream>
#include <iostream>
using std::endl;
using std::cout;
using std::ifstream;
using std::ofstream;
using std::ios_base;

Bestand::Bestand(const string& filename)
	: m_filename( filename )
{
	m_data = "";
	ifstream input( filename.c_str() );
	if( input.is_open() )
	{
		// TODO: gebruikt getline en buffer om efficienter te maken indien nodig.
		while (input.good())     // loop while extraction from file is possible
			m_data += static_cast<char>(input.get());
	}
	input.close();
}

void Bestand::setData( const string& data )
{
	cout << data << endl;
	m_data = data;
	ofstream output( m_filename.c_str(), ios_base::out | ios_base::trunc );
	for(size_t i = 0; i < data.size(); i++)
		output.put( data[i] );	

	output.close();
}

bool Bestand::bestaat()
{
	ifstream input( m_filename.c_str() );
	if( input.is_open() )
	{
		input.close();
		return true;
	}
	return false;
}
